package demoxsgl_300.com.gouwu1500.adapter;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;



import java.util.List;

import demoxsgl_300.com.gouwu1500.R;

public class GridViewAdapter extends BaseAdapter {

    public Activity context;
    public List<String> list;


    public GridViewAdapter(Activity context, List<String> data) {
        this.context = context;
        this.list = data;



    }

    @Override
    public int getCount() {
        if (list != null && list.size() > 6) {
            return 6;
        } else {
            return list.size();
        }
    }

    @Override
    public Object getItem(int arg0) {
        return list.get(arg0);
    }

    @Override
    public long getItemId(int arg0) {
        return arg0;
    }


    @Override
    public View getView(final int position, View view, ViewGroup arg2) {
        final Holder holder;
        if (view == null) {
            view = LayoutInflater.from(context).inflate(R.layout.item_gridview, null);
            holder = new Holder();
            holder.imageView = (TextView) view.findViewById(R.id.text);

            view.setTag(holder);
        } else {
            holder = (Holder) view.getTag();
        }
        holder.imageView.setText(list.get(position));



        return view;
    }

    class Holder {
        TextView imageView;
    }


}
